<template>
	<view class="">
		<view class="container">
			<view v-show="current === 0">
				<swiper :indicator-dots="true" :autoplay="true" indicator-color="#ccc" indicator-active-color="#007aff"
					:interval="3000" :duration="1000">
					<swiper-item v-for="item in banner">
						<view class="swiper-item">
							<image :src="baseUrl+item.advImg" style="width: 100%;" mode=""></image>
						</view>
					</swiper-item>
				</swiper>
				<uni-search-bar @confirm="search" @cancel="getZhaoPing()" placeholder="请输入职位名称" bgColor="white"
					style="margin-top: 10px;" />
				<uni-card title="热门职位" style="margin-top: 10px;">
					<view class="" style="display: flex;flex-wrap: wrap;">
						<view v-for="(item,index) in hot" @click="getZhaoPing(null,item.id)"
							style="width: 33.3%;margin-bottom: 10px;" :key="index">
							<view class="item">{{item.professionName}}</view>
						</view>
					</view>
				</uni-card>
				<uni-card title="职位列表" style="margin-top: 10px;" v-if="zhiweiList.length>0">
					<view v-for="(item,index) in zhiweiList" :key="index" @click="to(item.id)">
						<view class="item">职位名称：{{item.name}}</view>
						<view class="item">岗位职责：{{item.obligation}}</view>
						<view class="item">公司地点：{{item.address}}</view>
						<view class="item">薪资待遇：{{item.salary}}</view>
						<view class="line"></view>
					</view>
				</uni-card>
				<noData v-else></noData>
			</view>
			<view v-show="current === 1">
				<view v-for="(item,index) in jilu" style="margin-bottom: 10px;" :key="index">
					<uni-card>
						<view class="item">岗位名称：{{item.postName}}</view>
						<view class="item">公司名称：{{item.companyName}}</view>
						<view class="item">薪资：{{item.money}}</view>
						<view class="item">投递简历时间：{{item.satrTime}}</view>
					</uni-card>
				</view>
			</view>
			<view v-show="current === 2">
				<uni-card title="基本信息" extra="修改" style="margin-top: 0px;" @click="modifyInfo">
					<view class="" style="display: flex;align-items: center;">
						<image :src="avatar" style="height: 55px;width: 55px;border-radius: 55px;" @error="err" mode="">
						</image>
						<view class="item" style="margin-left: 10px;">{{user.userName}}</view>
					</view>
					<view class="item" style="margin-top: 5px;">用户昵称：{{user.nickName}}</view>
					<view class="item">邮件：{{user.email}}</view>
					<view class="item">电话号码：{{user.phonenumber}}</view>
					<view class="item">性别：{{user.sex==0?'男':'女'}}</view>
				</uni-card>
				<uni-card title="求职信息" extra="修改" style="margin-top: 10px;" v-if="data" @click="modify(data)">
					<view class="item">工作经验：{{data.experience}}</view>
					<view class="item">最高学历：{{data.mostEducation}}</view>
					<view class="item">现居住地：{{data.address}}</view>
					<view class="item">期望职位：{{data.positionId}}</view>
					<view class="item">薪资：{{data.money}}</view>
					<view class="item">自我描述：{{data.individualResume}}</view>
					<view class="item">教育经历：{{data.education}}</view>
					<view class="item">工作经历：{{data.experience}}</view>
				</uni-card>
				<noData @click="add" v-else msg="新建简历"></noData>
			</view>
		</view>
		<view class="tabbar">
			<view v-for="(item,index) in list" @click="sw(item,index)" style="text-align: center;" :key="index">
				<image style="height: 24px;width: 24px;" v-if="current===index" :src="item.selectedIconPath" mode="">
				</image>
				<view class="" style="color: #007aff;" v-if="current===index">{{item.text}}</view>

				<image style="height: 24px;width: 24px;" v-if="current!==index" :src="item.iconPath" mode=""></image>
				<view class="" v-if="current!==index">{{item.text}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				"list": [{
						"text": "找工作",
						"pagePath": "pages/home/home",
						"iconPath": "/static/home.png",
						"selectedIconPath": "/static/home_selected.png"
					},
					{
						"text": "投递记录",
						"pagePath": "pages/smart/smart",
						"iconPath": "/static/smart.png",
						"selectedIconPath": "/static/smart_selected.png"
					},
					{
						"text": "个人简历",
						"pagePath": "pages/personal/personal",
						"iconPath": "/static/personal.png",
						"selectedIconPath": "/static/personal_selected.png"
					}
				],
				banner: [],
				hot: [],
				zhiweiList: [],
				jilu: [],
				user: {

				},
				avatar: "",
				data: {}
			};
		},
		onLoad(item) {

		},
		onReady() {
			this.get('/prod-api/api/rotation/list', {
				type: '2'
			}, ).then(res => {
				let data = res.rows
				this.banner = data
			})
			this.getZhiweiList()
			this.getZhaoPing()
		},
		onShow() {
			this.get('/prod-api/api/job/deliver/list', {
				pageSize: 20,
				pageNum: 1
			}, ).then(res => {
				// console.log(res);
				let data = res.rows
				this.jilu = data
				console.log("xxxxx");
				console.log(this.jilu);
			})
			this.user = uni.getStorageSync("user")
			this.avatar = this.baseUrl + "/prod-api" + this.user.avatar
			// 查询用户简历详情
			this.get('/prod-api/api/job/resume/queryResumeByUserId/' + uni.getStorageSync("user").userId, {

			}, ).then(res => {
				let data = res.data
				this.data = data
			})
		},
		methods: {
			modifyInfo(){
				uni.navigateTo({
					url: '../../personal/info/info',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			modify(item) {
				uni.navigateTo({
					url: 'modifyJianLi/modifyJianLi?data=' + JSON.stringify(item),
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			add() {
				uni.navigateTo({
					url: 'addJianLi/addJianLi',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			err() {
				this.avatar = "/static/tx.png"
			},
			to(id) {
				uni.navigateTo({
					url: 'detail/detail?id=' + id,
					success: res => {},
					fail: () => {},
					complete: () => {},
					events: {
						// 属性名
						result: e => {
							console.log(e);
							if (e == 500) {
								this.current = 2
							}
						}
					}
				});
			},
			getZhaoPing(name, id) {
				console.log(name, id);
				this.get('/prod-api/api/job/post/list', {
					name: name,
					professionId: id
				}, 1).then(res => {
					let data = res.rows
					this.zhiweiList = data
				})
			},
			getZhiweiList(name) {
				this.get('/prod-api/api/job/profession/list', {
					professionName: name
				}, ).then(res => {
					let data = res.rows.slice(0, 9)
					this.hot = data
				})
			},
			search(e) {
				this.getZhaoPing(e.value)
			},
			sw(item, index) {
				if (this.current === index) {
					return
				}
				this.current = index
			}
		}
	};
</script>

<style lang="scss">
	.container::after {
		content: "";
		display: block;
		height: 60px;
		width: 100%;
	}

	.tabbar {
		height: 50px;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-around;
		z-index: 99;
		background-color: rgb(247, 247, 250);
		border-top: 1px solid #ccc;
		font-size: 12px;
		align-items: center;
	}
</style>
